import QtQuick 2.0
import QtQuick.Controls 2.5

Item {
    id: element
    width: 850
    height: 580

    signal qmlSN_sqlWriteFinish()
    onQmlSN_sqlWriteFinish: {
        $sqlMcRecorder.qml_updateAlarmAndSendMsg()
    }

    function qmlSN_sqlAlarmWriteFinish(var_now,var_history)
    {
        page_4AlarmMsg_Now.clearModel()
        for(var i=0; i<var_now.length/3; i++)
            page_4AlarmMsg_Now.addModel(var_now[3*i], var_now[3*i+1], var_now[3*i+2])
        for(i=0; 4*i+3<var_history.length; i++)
            if(var_history[4*i+3]==="false")
                page_4AlarmMsg_History.addModelGreen(var_history[4*i], var_history[4*i+1], var_history[4*i+2])
            else
                page_4AlarmMsg_History.addModelRed(var_history[4*i+0], var_history[4*i+1], var_history[4*i+2])
    }

    //初始化，延时读取历史记录
    Component.onCompleted: timerOnCompleted.start()
    Timer{
        id:timerOnCompleted
        interval: 1000
        repeat: false
        triggeredOnStart: false
        property int thisCounter: 0
        onTriggered: {
            var t_var = $sqlMcRecorder.qml_queryTable2DRetVec1D("select data,time,content,setorreset from alarm_history")
            for(var t_var1=0; 4*t_var1+3<t_var.length; t_var1++)
                if(t_var[4*t_var1+3]==="false")
                    page_4AlarmMsg_History.addModelGreen(t_var[4*t_var1], t_var[4*t_var1+1], t_var[4*t_var1+2])
                else
                    page_4AlarmMsg_History.addModelRed(t_var[4*t_var1+0], t_var[4*t_var1+1], t_var[4*t_var1+2])
        }
    }

    SwipeView{
        id:swipeView_this
        orientation: Qt.Horizontal
        clip: true
        currentIndex: 0
        width: parent.width
        height: parent.height*0.8

        Page_04AlarmMsg_Now {
            id: page_4AlarmMsg_Now
            width: swipeView_this.width
            height: swipeView_this.height
        }
        Page_04AlarmMsg_History {
            id: page_4AlarmMsg_History
            width: swipeView_this.width
            height: swipeView_this.height
        }
        /*Item {
            id: firstPage
//            anchors.fill: parent
            Page_4AlarmMsg_Now {
                id: page_4AlarmMsg_Now
                width: swipeView_this.width
                height: swipeView_this.height
            }
        }
        Item {
            id: secondPage
            Page_4AlarmMsg_History {
                id: page_4AlarmMsg_History
                width: swipeView_this.width
                height: swipeView_this.height
            }
        }*/

        onCurrentIndexChanged: {
//            print(swipeView_this.currentIndex)
            if(swipeView_this.currentIndex==0){
                button.checked = true
                button2.checked = false
            }
            else{
                button.checked = false
                button2.checked = true
            }
        }
    }


    EXC_Normal_BtnSytle {
        id: button
        nameText: qsTr("实时报警")
        width: parent.width*0.15
        checked: true
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.3
        anchors.topMargin: parent.height/20
        anchors.top: swipeView_this.bottom
        onClicked: {
            if(swipeView_this.currentIndex==0)
                checked = true;
            else
                swipeView_this.currentIndex = 0
//            if(button2.checked)
//                button2.checked = false
        }
    }

    EXC_Normal_BtnSytle {
        id: button2
        nameText: qsTr("历史报警")
        width: parent.width*0.15
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.6
        anchors.topMargin: parent.height/20
        anchors.top: swipeView_this.bottom
        onClicked: {
            if(swipeView_this.currentIndex==1)
                checked = true;
            else
                swipeView_this.currentIndex = 1

//            if(button.checked)
//                button.checked = false
        }
    }
}

/*##^##
Designer {
    D{i:0;formeditorZoom:0.5}
}
##^##*/
